package com.yulongtian.weekCompetition.month202211.week3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
 * @author yulongTian
 * @create 2022-11-20 11:35
 */
public class Test03 {
    public static void main(String[] args) {
        int[][] roads = {{3, 1}, {3, 2}, {1, 0}, {0, 4}, {0, 5}, {4, 6}};
        System.out.println(minimumFuelCost(roads, 2));
    }

    public static long minimumFuelCost(int[][] roads, int seats) {
        int res = 0;

        //map集合存储
        HashMap<Integer, Integer> roadsMap = new HashMap<>();

        for (int[] road : roads) {
            roadsMap.put(road[0], road[1]);
        }

        //根节点集合起点
        List<Integer> roots = new ArrayList<>();

        //获取所有键的集合
        Set<Integer> integers = roadsMap.keySet();

        //遍历键的集合，获取每个键：增强for循环
        for (Integer integer : integers) {
            //根据键去找值：get(Object key)
            Integer integer1 = roadsMap.get(integer);
            if (!integers.contains(integer1)) {
                roots.add(integer1);
            }
        }


        //反转
        HashMap<Integer, Integer> roadsMapReserve = new HashMap<>();
        for (int[] road : roads) {
            roadsMapReserve.put(road[1], road[0]);
        }
        for (Integer root : roots) {
            //每个根节点到首都的距离
            int temp = 0;
            int pre = root;
            while (pre != 0) {
                if (roadsMapReserve.containsKey(pre)) {
                    pre = roadsMapReserve.get(pre);
                } else {
                    pre = roadsMap.get(pre);
                }
                temp++;
            }
            System.out.println(temp);

        }


        return 0L;
    }

}
